﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Services;
using System.Web.Mvc.Ajax;
using System.IO;
using System.Text.RegularExpressions;
//using Microsoft.Office.Interop.Word;
//using System.Diagnostics; 
using System.IO;

namespace ajaxPractice.Controllers
{
    public class HomeController : Controller
    {
        public List<string> GetData(){
            List<string> list = new List<string>();
            list.Add("a");
            list.Add("b");
            list.Add("c");
            list.Add("d");
            list.Add("e");
            list.Add("f");
            list.Add("g");
            list.Add("h");
            list.Add("i");
            list.Add("j");
            list.Add("k");
            list.Add("l");
            list.Add("m");
            list.Add("n");
            list.Add("o");
            list.Add("p");
            list.Add("q");
            list.Add("r");
            list.Add("s");
            list.Add("t");
            list.Add("u");
            list.Add("v");
            list.Add("w");
            list.Add("x");
            list.Add("y");
            list.Add("z");
            list.Add("aa");
            list.Add("ba");
            list.Add("ca");
            list.Add("da");
            list.Add("ea");
            list.Add("fa");
            list.Add("ga");
            list.Add("ha");
            list.Add("ia");
            list.Add("ja");
            list.Add("ka");
            list.Add("la");
            list.Add("ma");
            list.Add("na");
            list.Add("oa");
            list.Add("pa");
            list.Add("qa");
            list.Add("ra");
            list.Add("sa");
            list.Add("ta");
            list.Add("ua");
            list.Add("va");
            list.Add("wa");
            list.Add("xa");
            list.Add("ya");
            list.Add("za");
            list.Add("ab");
            list.Add("bb");
            list.Add("cb");
            list.Add("db");
            list.Add("eb");
            list.Add("fb");
            list.Add("gb");
            list.Add("hb");
            list.Add("ib");
            list.Add("jb");
            list.Add("kb");
            list.Add("lb");
            list.Add("mb");
            list.Add("nb");
            list.Add("ob");
            list.Add("pb");
            list.Add("qb");
            list.Add("rb");
            list.Add("sb");
            list.Add("tb");
            list.Add("ub");
            list.Add("vb");
            list.Add("wb");
            list.Add("xb");
            list.Add("yb");
            list.Add("zb");
            return list;
        }
        // public ActionResult test1(string id)
        //{
        //    return Content(id + "返回一个字符串");
        //}
        public ActionResult test1()
        {
            List<string> templist = new List<string>();
            templist = GetData();
            double pageNum;
            pageNum = double.Parse(templist.Count().ToString())/5;//这个5决定前台一页有多少条信息
            return Content(Math.Ceiling(pageNum).ToString());
        }
        public ActionResult test2()
        {
            List<string> templist = new List<string>();
            templist.Add(GetData()[0]);
            templist.Add(GetData()[1]);
            templist.Add(GetData()[2]);
            templist.Add(GetData()[3]);
            templist.Add(GetData()[4]);
            return Json(templist);
        }
        public ActionResult test3(string id)
        {
            List<string> templist = new List<string>();
            for (int count = (int.Parse(id) - 1) * 5; count < (int.Parse(id) - 1) * 5 + 5 ; count++)
            {
                if (count == GetData().Count())
                {
                    break;
                }
                templist.Add(GetData()[count]);
            }
            return Json(templist);
        }




        public ActionResult getList()
        {
            return View();
        }
        public ActionResult te(string id)
        {
            
            return View();
        }
        public ActionResult tee(string id)
        {
            Response.Redirect("/Home/te");
            return View();
        }
        public ActionResult Page1()
        {
            Session["Login"] = "zhouyu";
            return View();
        }
        public ActionResult GoToPage2(string userData)
        {
            string userID="";
            string userPassword="";
            for (int i = 0; userData[i]!='/'; i++)
            {
                userID = userID + userData[i];
            }
            for (int i = userID.Length+1; i < userData.Length  ; i++)
            {
                userPassword = userPassword + userData[i];
            }
            return View();
        }
        public ActionResult Page2(){
            Session["Login"] = "zhanglibing";
            return View();
        }

        public ActionResult Page3()
        {
            Session["Login"] = "chendanyu";
            return View();
        }






        public ActionResult Index()
        {
            return View();
        }
        public ActionResult About()
        {
            return View();
        }

        public ActionResult Contact()
        {
            return View();
        }
        ////////////////////////////////////////////////////////////////////////////////////////////////

        #region 预览Pdf
        /// <summary>
        /// 预览Pdf
        /// </summary>
        public string PreviewPdf(string physicalPath, string url)
        {
            return Server.UrlDecode(url);
        }
        #endregion
        #region
        /// <summary>
        /// 读取PDF文件
        /// </summary>
        /// public FileStreamResult readPDF(){
        /// return File(fs, "application/pdf");
        /// }
        /// <param name="fName">文件名称(可以从其他地方传进来)</param>
        /// <returns></returns>
        public ActionResult PDFPlayer()
        {
            ViewBag.PDF = "/PDF/开心就好.pdf";
            string filename = "开心就好.pdf";
            string url = @"~/PDF/开心就好.pdf";
            string pdfSrc = Server.MapPath(Server.UrlDecode(url));
            FileStream fs = new FileStream(pdfSrc, FileMode.Open, FileAccess.Read);
            Regex regexp = new Regex(@"\.pdf$", RegexOptions.IgnoreCase);
            if (regexp.IsMatch(filename))
            {
                StreamReader sr = new StreamReader(fs);
                string pdfText = sr.ReadToEnd();
                regexp = new Regex(@"/Type\s*/Page[^s]");
                MatchCollection matches = regexp.Matches(pdfText);
                string height = (matches.Count * 1040).ToString() + "px";
                ViewBag.PDFHeight = height;
            }
            return View();
        }
        #endregion
    }
}